/**
 * zmn文章模块-文章列表
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author daizc
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function () {
    window.$ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let table = layui.table;

    var cols = [
        [
            { type: 'numbers', title:'序号',align:'center'},
            { field:'name', title:'配件',align:'center'},
            { field:'unit', title:'一级单位',align:'center'},
            { field:'scale', title:'一级换算比例',align:'center'},
            { field:'unitTwo', title:'二级单位',align:'center'},
            { field:'scaleTwo', title:'二级换算比例',align:'center'},
            { field:'unitThree', title:'三级单位',align:'center'},
            { field:'creater', title:'创建人',align:'center', templet:d=>{
                if (d.creater) {
                    return d.creater;
                }
                else {
                    return '--';
                }
                }},
            { field:'createTime', title:'创建时间',align:'center', templet: '<div>{{zmnUtil.createTime(d.createTime)}}</div>'},
            {fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#zmn-part-table-bar'}
        ]
    ];

    table.render({
        elem:    "#zmn-part-table",
        toolbar: "#zmn-part-table-tool",
        defaultToolbar: ['filter'],
        title:   "配件单位换算管理",
        data: json.items,
        limit: 10000,
        cols: cols,
        height: 'full-214'
    });


    //监听表单提交
    form.on('submit(zmn-part-unit-submit)', function (data) {
        layer.confirm('确认添加配件单位换算?', {icon: 3}, function (index) {
            zmnLayUtil.ajaxResultDTOJson(parent.layui.layer, "/part/unit/ajax/addEdit.action", data.field, 0, function () {
                location.reload();
            });
            layer.close(index);
        });
        return false;
    });

    //【表格右侧工具栏监听】
    table.on('tool(zmn-part-table)', function (obj) {
        let skuId = obj.data.skuId;
        if (obj.event === 'del') {
            layer.confirm('确认删除配件关联?', {icon: 3}, function (index) {
                zmnLayUtil.ajaxResultDTOUE(parent.layui.layer, "/part/unit/ajax/del.action", {skuId: skuId}, 0, function () {
                    location.reload();
                });
                layer.close(index);
            });
        }
    });
});